<template>
  <el-dialog
    title="查看回复与操作"
    :visible.sync="dialogVisible"
    width="50%"
  >
    <div class="consuit-main">
      <div class="consuit-title">咨询信息</div>
      <!--      <div class="title">-->
      <!--        <label>标题：</label>-->
      <!--        <div>{{ datalist.title }}</div>-->
      <!--      </div>-->
      <div class="context">
        <label>描述：</label>
        <div>{{ datalist.context }}</div>
      </div>
      <div class="quizzer">
        <label>咨询人：</label>
        <div>{{ datalist.quizzer }}</div>
      </div>
    </div>
    <div v-if="countAnswer > 0" class="assign">

      <!-- 如果有指派人员答复就显示指派员答复的信息则不能再操作指派，否则显示指派操作 -->
      <div class="consuit-main">
        <div class="consuit-title">答复信息</div>
        <li v-for="(item, index) in answerList" :key="index">
          <div class="quizzer title annewshhang">
            <label>答复：</label>
            <div>{{ item.solution }}</div>
          </div>
          <div class="quizzer title">
            <div class="answer-name-time">
              <span>答复人：</span>{{ item.reply }}
              <span style="margin-left:20px">回复时间：</span>{{ item.cTime }}
            </div>
          </div>
        </li>
      </div>
    </div>
    <div v-else class="assign-main">
      <div class="consuit-main">
        <div class="consuit-title">选择回复律师</div>
        <div class="quizzer title">
          <label>回复律师</label>
          <el-select v-model="value" placeholder="请选择" style="width:250px" @change="changeuserName(value)">
            <el-option
              v-for="item in options"
              :key="item.id"
              :label="item.nickName"
              :value="item.id"
            />
          </el-select>
        </div>
      </div>

    </div>

    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="confirm">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
export default {
  data() {
    return {
      dialogVisible: false, // 弹窗开关
      datalist: {}, // 获取table列表数据
      options: [], // 指派人员列表
      value: '',
      answerList: [], // 回复问题信息内容
      countAnswer: '', // 答复次数
      name: '',
      val: ''
    }
  },
  methods: {
    // 获取指派人员名字
    changeuserName(val) {
      console.log(this.options)
      let name
      for (let i = 0; i < this.options.length; i++) {
        if (val === this.options[i].id) {
          name = this.options[i].nickName
        }
      }
      this.name = name
      this.val = val
      // this.determine(name, val)
    },
    confirm() {
      this.determine(this.name, this.val)
    },
    determine(name, val) {
      if (this.options === '') {
        this.dialogVisible = false
      } else {
        if (this.value !== '') {
          this.$confirm('您确定要把该问题指派给' + name + '?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.$emit('postDispatchQuestion', val)

            this.$message({
              type: 'success',
              message: '指派成功!'
            })
            this.dialogVisible = false
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消指派'
            })
          })
        }
      }
    }
  }
}
</script>
<style>
.el-dialog__body{
    padding-top: 20px!important;
}
.consuit-main{
    width: 96%;
    height: auto;
    border: 1px solid #ccc;
    padding: 10px 2%;
    border-radius: 5px;
    position: relative;
}
.consuit-main li{
  list-style: none;
  border-bottom: 1px solid #ccc;
  padding-bottom: 5px;
}
.consuit-main li:last-child{
  border-bottom: none;
}
.annewshhang{
  text-indent: 24px;
}
.consuit-title{
    position: absolute;
    top: -10px;
    margin-bottom: 10px;
    font-weight: 500;
    font-size: 1.1rem;
    width: 110px;
    height: 30px;
    text-align: center;
    background: #fff;
}
.title,.context,.quizzer{
    width: 100%;
    display: flex;
    color: #999;
    text-align: justify;
}
.title label,.context label,.quizzer label{
    width: 12%;
    text-align: right;
    margin-right: 2%;
}
.title div,.context div,.quizzer div{
    width: 86%;
}
.title{
    line-height: 20px;
    margin-top: 15px;
    margin-bottom: 0;
}
.context{
    margin: 10px auto;
    line-height: 20px;
}

.assign{
    position: relative;
    margin-top: 25px;
}
.assign-main{
    width: 100%;
    margin-top: 40px;
}
.assign-main label{
    margin-right: 10px;
    margin-top: 6px;
}
.answer-name-time{
  width: 100%!important;
  position: relative;
  right: 10px;
  text-align: right;
}
</style>
